#====================================================================
# MEDIA GATEWAY MAKEFILE
#====================================================================
COMMON_DIR := ./../common
PROTOCOLS_DIR := ./../protocols

BINARIES=mediaGateway

INC_PATH += -I/usr/include
#INC_PATH += -I$(COMMON_DIR)/daemon/include
INC_PATH += -I$(COMMON_DIR)/log/include
#INC_PATH += -I$(COMMON_DIR)/parser/include
INC_PATH += -I$(COMMON_DIR)/socket/include
INC_PATH += -I$(COMMON_DIR)/generator_framework/include
INC_PATH += -I$(COMMON_DIR)/media/include
INC_PATH += -I$(PROTOCOLS_DIR)/source
INC_PATH += -I./include/
INC_PATH += -I./mgw_gap/include \
			-I./mgw_gap/events/include \
			-I./mgw_gap/states/include
INC_PATH += -I./media_conn/include \
			-I./media_conn/events/include \
			-I./media_conn/states/include

vpath %.cc \
$(COMMON_DIR)/daemon/source:\
$(COMMON_DIR)/log/source:\
$(COMMON_DIR)/parser/source:\
$(COMMON_DIR)/socket/source:\
$(COMMON_DIR)/generator_framework/source:\
$(COMMON_DIR)/media/source:\
$(PROTOCOLS_DIR)/source:\
./source:\
./mgw_gap/source:./mgw_gap/states/source:\
./media_conn/source:./media_conn/states/source:\


CC := g++
LD := g++

LIB_STATIC = /usr/lib/libprotobuf.a
#LIB_STATIC += /usr/lib/libboost_system.a
#LIB_STATIC += /usr/lib/libboost_thread.a


LIB_DYNAMIC := -L/usr/lib -L/usr/local/lib -lprotobuf \
	 -lboost_system -lboost_thread 


CCFLAGS := -Wall -g -O0 -c $(INC_PATH) -pthread
LDFLAGS := -Wall -g -pthread

DIR_OBJ := obj

$(DIR_OBJ)/%.o:%.cc
	@[ -d $(DIR_OBJ) ] || mkdir -p $(DIR_OBJ)
	@echo "Compiling ($@)"
	$(CC) $(CCFLAGS) -o $@ $<

################################################################################
#
# 
#
################################################################################
default: all

all: $(BINARIES)

clean:
	@echo "Removing object files and binaries"
	rm -fr $(DIR_OBJ)
	rm -f $(BINARIES)

################################################################################
#
# Server
#
################################################################################
# Generation of list of .o files

#######################################################
# common sources
#OBJECTS += $(patsubst %.cc, %.o, $(notdir $(wildcard \
	$(COMMON_DIR)/daemon/source/*.cc)))
OBJECTS += $(patsubst %.cc, %.o, $(notdir $(wildcard \
	$(COMMON_DIR)/generator_framework/source/*.cc)))
OBJECTS += $(patsubst %.cc, %.o, $(notdir $(wildcard \
	$(COMMON_DIR)/log/source/*.cc)))
OBJECTS += $(patsubst %.cc, %.o, $(notdir $(wildcard \
	$(COMMON_DIR)/media/source/*.cc)))	
#OBJECTS += $(patsubst %.cc, %.o, $(notdir $(wildcard \
	$(COMMON_DIR)/parser/source/*.cc)))
OBJECTS += $(patsubst %.cc, %.o, $(notdir $(wildcard \
	$(COMMON_DIR)/socket/source/*.cc)))	
#######################################################
# mgw main sources	
OBJECTS += $(patsubst %.cc, %.o, $(notdir $(wildcard \
	./source/*.cc)))

#######################################################
# mgw_gap sources
OBJECTS += $(patsubst %.cc, %.o, $(notdir $(wildcard \
	./mgw_gap/source/*.cc)))
OBJECTS += $(patsubst %.cc, %.o, $(notdir $(wildcard \
	./mgw_gap/states/source/*.cc)))
	
#######################################################
# media_conn sources
OBJECTS += $(patsubst %.cc, %.o, $(notdir $(wildcard \
	./media_conn/source/*.cc)))
OBJECTS += $(patsubst %.cc, %.o, $(notdir $(wildcard \
	./media_conn/states/source/*.cc)))	
#######################################################
# GAP, common - protocol definitions
OBJECTS += common.pb.o GAP.pb.o UAP.pb.o
	
mediaGateway: $(addprefix $(DIR_OBJ)/,$(OBJECTS)) 
	$(LD) $(LDFLAGS) $^ -L/usr/lib -L/usr/local/lib -lboost_system -lboost_thread -lprotobuf -lrt -o $@ 

#.SILENT :